package inz.common;

import java.text.DecimalFormat;

import org.tartarus.snowball.SnowballStemmer;

/** class holding different utilities */
public class MyUtils
{
	/** rounds double to 2 places after coma */
	public static DecimalFormat doubleFormat = new DecimalFormat();
	private static SnowballStemmer stemmer;

	static
	{
		try
		{
			Class<?> stemClass = Class.forName("org.tartarus.snowball.ext.englishStemmer");
			stemmer = (SnowballStemmer) stemClass.newInstance();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		doubleFormat.setMaximumFractionDigits(3);
		doubleFormat.setMinimumFractionDigits(2);
	}

	/** stemming a word to its core
	 * @param word word to stem
	 * @return stemmed word */
	public static String stem(String word)
	{
		stemmer.setCurrent(word);
		stemmer.stem();
		return stemmer.getCurrent();
	}

}
